<template>
  <div>
    <div v-if="filePath">
      <div v-for="(item) in filePath.split('|')" :key="item">
        <el-link @click="readFile(item)">{{ item.split('/')[3] }}</el-link>
      </div>
    </div>
  </div>
</template>>

<script>
import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth'
import { readFile } from '@/api/basic/file'

export default {
  props: {
    filePath: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      can: false,
      headers: { 'Authorization': getToken() }
    }
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ])
  },
  watch: {
    filePath: function(val) {
      this.can = !!val
    }
  },
  methods: {
    readFile(filePath) {
      console.log(filePath)
      readFile(filePath).then(res => {
        console.log(res)
        if (res) {
          filePath = filePath.substring(0, filePath.lastIndexOf('.')) + '.pdf'
          window.open(this.baseApi + filePath)
        } else {
          this.$message.error('该文件不存在')
        }
      })
    }
  }

}
</script>
